<?php
include($classes_path.'/class.postTable.php');
$postGetter = new postTable();
$postGetter->set_page($pageid);
$postGetter->set_id($article);
$postGetter->set_cat($cat);
$postGetter->set_tag($tag);

switch($pageid) {
    case "1"; //home
    case "201"; //archive
    case "drafts";

        $postsToday = $postGetter->get_posts_today();

        if(!empty($postsToday)) { ?>
<table class="items" cellspacing="0">
    <tr class="first">
        <td></td>
        <td>
            <h3><?php print($postGetter->get_tableTitle()); ?></h3>
        </td>
        <td></td>
                    <?php if($_SESSION['adminrights'] == true) { ?>
        <td></td>
        <td></td>
                    <?php } ?>
    </tr>

                <?php foreach($postsToday as $todaypost) { ?>
    <tr class="<?php print($todaypost['class']); ?>">
        <td align="center"><span class="<?php print(strtolower($todaypost['category'])); ?>"></span></td>
        <td>
            <a href="page/2/news/article/<?php print($todaypost['id'].'/'.htmlentities(strtolower(str_replace( " ", "-", $todaypost['title']))).URL_EXTENSION); ?>" title="<?php print($todaypost['title']); ?>"><span class="time"><?php print($todaypost['time']); ?></span><?php print($todaypost['title']); ?></a>
        </td>
                        <?php if($_SESSION['adminrights'] == true) {?>
        <td align="right">
            <a href="page/8/admin/apage/edit/epage/2/article/<?php print($todaypost['id']); ?>">Edit</a>
        </td>
        <td align="right">
            <a href="../includes/delete.inc.php?pageid=2&article=<?php print($todaypost['id']); ?>" onclick="javascript:return confirm(<?php print($delPromt) ?>)">[X]</a>
        </td>
                        <?php } ?>
        <td align="right">
            <span class="grey"><?php print($todaypost['count']); ?></span>
        </td>
    </tr>
                <?php } ?>
</table>
        <?php
        }
        break;
}

switch($pageid) {
    case "1"; //home

        $lastWeeksPosts = $postGetter->get_lastWeeks_posts();

        if(!empty($lastWeeksPosts)) { ?>
<table class="items" cellspacing="0">

    <tr class="first">
        <td></td>
        <td>
            <h3>This weeks news</h3>
        </td>
        <td></td>
                    <?php if($_SESSION['adminrights'] == true) { ?>
        <td></td>
        <td></td>
                    <?php } ?>
    </tr>

                <?php foreach($lastWeeksPosts as $weeks_post) { ?>
    <tr class="<?php print($weeks_post['class']); ?>">
        <td align="center"><span class="<?php print(strtolower($weeks_post['category'])); ?>"></span></td>
        <td>
            <a href="page/2/news/article/<?php print($weeks_post['id'].'/'.htmlentities(strtolower(str_replace( " ", "-", $weeks_post['title']))).URL_EXTENSION); ?>" title="<?php print($weeks_post['title']); ?>"><span class="time"><?php print($weeks_post['time']); ?></span><?php print($weeks_post['title']); ?></a>
        </td>
                        <?php if($_SESSION['adminrights'] == true) { ?>
        <td align="right">
            <a href="page/8/admin/apage/edit/epage/2/article/<?php print($weeks_post['id']); ?>">Edit</a>
        </td>
        <td align="right">
            <a href="../includes/delete.inc.php?pageid=2&article=<?php print($weeks_post['id']); ?>" onclick="javascript:return confirm(<?php print($delPromt) ?>)">[X]</a>
        </td>
                        <?php } ?>
        <td align="right">
            <span class="grey"><?php print($weeks_post['count']); ?></span>
        </td>
    </tr>
                <?php } ?>
</table>
        <?php
        }
        break;
}

switch($pageid) {
    case "1"; //home

        $latestPosts = $postGetter->get_latest_posts();

        if(!empty($latestPosts)) { ?>
<table class="items" cellspacing="0">

    <tr class="first">
        <td></td>
        <td>
            <h3>latest 20 posts</h3>
        </td>
        <td></td>
                    <?php if($_SESSION['adminrights'] == true) { ?>
        <td></td>
        <td></td>
                    <?php } ?>
    </tr>

                <?php foreach($latestPosts as $late_post) { ?>
    <tr class="<?php print($late_post['class']); ?>">
        <td align="center"><span class="<?php print(strtolower($late_post['category'])); ?>"></span></td>
        <td>
            <a href="page/2/news/article/<?php print($late_post['id'].'/'.htmlentities(strtolower(str_replace( " ", "-", $late_post['title']))).URL_EXTENSION); ?>" title="<?php print($late_post['title']); ?>"><span class="time"><?php print($late_post['time']); ?></span><?php print($late_post['title']); ?></a>
        </td>
                        <?php if($_SESSION['adminrights'] == true) { ?>
        <td align="right">
            <a href="page/8/admin/apage/edit/epage/2/article/<?php print($late_post['id']); ?>">Edit</a>
        </td>
        <td align="right">
            <a href="../includes/delete.inc.php?pageid=2&article=<?php print($late_post['id']); ?>" onclick="javascript:return confirm(<?php print($delPromt) ?>)">[X]</a>
        </td>
                        <?php } ?>
        <td align="right">
            <span class="grey"><?php print($late_post['count']); ?></span>
        </td>
    </tr>
                <?php } ?>
</table>
        <?php
        }
        break;
}
?>
